/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

/*
    SPDX-FileCopyrightText: 1998 Luca Montecchiani <m.luca@usa.net>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "ui_dateandtime.h"

#include <QCheckBox>
#include <QComboBox>
#include <QPaintEvent>
#include <QSpinBox>
#include <QTime>
#include <QTimer>
#include <QWidget>

#include <KDatePicker>

class Kclock;
class QTimeEdit;
class SlipButton;
namespace Plasma
{
class Svg;
}

class Dtime : public QWidget, public Ui::DateAndTime
{
    Q_OBJECT
public:
    explicit Dtime(QWidget *parent, bool haveTimedated);

    void processHelperErrors(int code);
    void load();
    void save();


    QStringList ntpServers() const;
    bool ntpEnabled() const;

    QDateTime userTime() const;
    QString quickHelp() const;
    void updateHourFormat();
    void updateConfigFile(bool use24hFormat);
    void saveConfig();
    void updateCurrentHour();

    bool ntpEnabledChanged() {return m_initialNtpEnabled != ntpEnabled();}
    bool userTimeChanged() {return m_initialUserTime != userTime();}

Q_SIGNALS:
    void timeChanged(bool);
    void FormatconfigChanged(bool);

private Q_SLOTS:
    void configChanged();
    void serverTimeCheck();
    void timeout();
    void set_time();
    void changeDate();

    void onYearChanged(int index);
    void onMonthChanged(int index) ;
    void onDayChanged(int index);
    void setAutoCheck();

public:
    bool hasTimeOrNtpChanges() const;//changed by gy
    bool hasDateFormatChanges() const;

private:
    void findNTPutility();
    void updateDays(int year, int month);

    QString ntpUtility;

    QTimeEdit *timeEdit;

    Kclock *kclock;

    QTime time;
    QDate date;
    QTimer internalTimer;

    QString timeServer;
    int BufI;
    bool refresh;
    bool ontimeout;
    bool m_haveTimedated;

    SlipButton *setDateTimeAuto;
    SlipButton *setDateFormat;
    bool m_use24hFormat;
    bool m_isDateFormatDirty = false;

public:
    bool m_ischecked;

private:
    bool m_initialNtpEnabled;//changed by gy
    bool m_initialAmAndPm;
    QDateTime m_initialUserTime;
    bool m_initialUse24hFormat;
};


